package com.yy.jhl.ui.manager.presenter;

import com.google.gson.Gson;
import com.yy.common.commonutils.StringUtil;
import com.yy.jhl.api.Api;
import com.yy.jhl.api.RxSubscriber;
import com.yy.jhl.app.AppConstant;
import com.yy.jhl.bean.ProjectInfo;
import com.yy.jhl.ui.manager.contract.MenuOneContract;
import com.yy.jhl.ui.manager.contract.MenuThreeContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.FormBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * Created by Ellis.Li on 2017/8/30.
 */

public class MenuOnePresenter extends MenuOneContract.Presenter {
    @Override
    public void getProjectList( int page, String projectName) {
        Map<String, Object> requestMap = new HashMap<>();
        requestMap.put("type",3);
        requestMap.put("page_size", AppConstant.PAGE_SIZE);
        requestMap.put("page",page);
        if (!StringUtil.isEmpty(projectName)){
            requestMap.put("project_name",projectName);
        }
        mRxManage.addSubscription(Api.getDefault().getProjectList(requestMap), new RxSubscriber<ResponseBody>(mContext,false) {
            @Override
            protected void _onNext(String result) {
                ProjectInfo projectInfo = new Gson().fromJson(result,ProjectInfo.class);
                mView.getProjectSuccess(projectInfo);
            }

            @Override
            protected void _onError(String message) {
                mView.getProjectListFail();
            }
        });
    }

    @Override
    public void getCollectList(int page) {
        Map<String, Object> requestMap = new HashMap<>();
//        requestMap.put("type",3);
        requestMap.put("page_size", AppConstant.PAGE_SIZE);
        requestMap.put("page",page);
        mRxManage.addSubscription(Api.getDefault().getCollectList(requestMap), new RxSubscriber<ResponseBody>(mContext,false) {
            @Override
            protected void _onNext(String result) {
                ProjectInfo projectInfo = new Gson().fromJson(result,ProjectInfo.class);
                mView.getProjectSuccess(projectInfo);
            }

            @Override
            protected void _onError(String message) {
                mView.getProjectListFail();
            }
        });
    }
}
